window.onload = run;
$(window).bind("scroll", function () { toTopHide() });

function run() {
    setInterval("getCalendar()", 500);
}

function getCalendar() {
    //新建一个Date对象
    var today = new Date();

    //分別获得年月日
    var year = today.getFullYear();
    var month = today.getMonth() + 1;
    var day = today.getDate();

    //获得星期几
    var weekday = new Array(7);
    weekday[0] = "星期日";
    weekday[1] = "星期一";
    weekday[2] = "星期二";
    weekday[3] = "星期三";
    weekday[4] = "星期四";
    weekday[5] = "星期五";
    weekday[6] = "星期六";

    //获得时分秒
    var hour = today.getHours();
    hour = check(hour);
    var min = today.getMinutes();
    min = check(min);
    var sec = today.getSeconds();
    sec = check(sec);
    document.getElementById("calendar").innerHTML = year + "年" + month + "月" + day + "日" + "  " + weekday[today.getDay()] + " " + hour + ":" + min + ":" + sec;

    //效果同run()方法
    //setTimeout("getCalendar()", 500);
}

function check(x) {
    if (x < 10) {
        x = "0" + x;
    }
    return x;
}




function toTopHide() {
    document.documentElement.scrollTop + document.body.scrollTop > 400 ? (document.getElementById("toTop").style.display = "block") : (document.getElementById("toTop").style.display = "none")
}